package leetcode_2401_2500;

public class LeeCode_2412 {
    public static void main(String[] args) {
        System.out.println(minimumMoney(new int[][]{{2, 1}, {5, 0}, {4, 2}}));
        System.out.println(minimumMoney(new int[][]{{3, 0}, {0, 3}}));
        System.out.println(minimumMoney(new int[][]{{8, 0}}));
    }
    private static long minimumMoney(int[][] transactions) {
        long total = 0, mx = 0;
        for (int[] t : transactions) {
            total += Math.max(0, t[0] - t[1]);
            mx = Math.max(mx, Math.min(t[0], t[1]));
        }
        return total + mx;
    }
}